package itheima.com.Day12;

import java.io.*;
import java.util.Arrays;

public class CharStream14 {
    //将文件从本地读取出来并进行重新排序与便利  如：6 9 10 3 5 2 4 1 7 8
    public static void main(String[] args) throws IOException {
        //可以使用字符缓冲流高效读取  一次读取一整行,用FileReader读只能每次读取一个一个字符，读到10还需要拼接
     BufferedReader br = new BufferedReader(new FileReader("Master\\z.txt"));
      //将数据读取并进行切割，得到字符串数组
        String s =br.readLine();
        String[] s1 = s.split(" ");
        //将字符串数组转换成int数组便于排序
        int[] arr = new int[s1.length];
        for (int i = 0; i < arr.length; i++) {
           // String s2 = ;
            int i1 = Integer.parseInt(s1[i]);
            arr[i] = i1;
        }
        Arrays.sort(arr);
        System.out.println(Arrays.toString(arr));

        BufferedWriter bw = new BufferedWriter(new FileWriter("Master\\z.txt"));
        for (int i = 0; i < arr.length; i++) {
            bw.write(arr[i]+" ");
            bw.flush();
        }
        bw.close();

    }
}
